﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;

namespace frm_medic
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void Form4_Load(object sender, EventArgs e)
        {
            ArrayList list = new ArrayList();
            string sql = "select drug from drug";
            string conStr = "Data Source=DESKTOP-CM2RP4R;Initial Catalog=medic;Integrated Security=SSPI";
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();

                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                DataTable dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(dr[0].ToString().Trim());
                }
                comboBox1.DataSource = list;
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally
            {
                con.Close();
            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string conStr = "Data Source=DESKTOP-CM2RP4R;Initial Catalog=medic;Integrated Security=SSPI";
            SqlConnection con = new SqlConnection(conStr);
            try
            {

                con.Open();
                string sql = "select ef_time from drug where drug='" + comboBox1.Text + "'";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Connection = con;
                SqlDataReader da = cmd.ExecuteReader();
                while (da.Read())
                {
                    string dt1 = da[0].ToString();
                    string dt2=dateTimePicker1.Value.ToString("yyyy/MM/dd");
                    DateTime t1 = Convert.ToDateTime(dt1);
                    DateTime t2 = Convert.ToDateTime(dt2);
                    if (t1 < t2)
                    {
                        MessageBox.Show("药品过期");
                    }
                    else
                    {
                        MessageBox.Show("药品未过期");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally
            {

                con.Close();

            }
        }
    }
}
